package testIntergration;

import static org.junit.Assert.*;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;


import FamilyTherapy.MagicToolCard;
import FamilyTherapy.Player;

public class testMagicToolCard_beDescisionMaker {

	@Before
	public void setUp() throws Exception {
	}

	@After
	public void tearDown() throws Exception {
	}
	@Test
	public void testBeDescisionMaker_1() 
	{
		//initialise variable
		int result;
		Player[] p ={new Player("a",1),new Player("b",2)};

		//for output
		final ByteArrayOutputStream outContent = new ByteArrayOutputStream();
		System.setOut(new PrintStream(outContent));		
	
		MagicToolCard m = new MagicToolCard();	
		
		String expected = "Now, you use this card to be DecisionMaker!\n" +
		"The decision maker is: b.\n" +
		"Please input your decision (1-4): \n";
		
		//for input
		String data = "1"; 	//data to be input 
		InputStream stdin = System.in; 
		try {   
			System.setIn(new ByteArrayInputStream(data.getBytes()));	//put data to input stream
			result = m.beDescisionMaker(1,p);	//for getting data from input stream
		} 
		finally {  
			System.setIn(stdin); 	//reset input stream as System.in
		} 
		
		//for testing
		assertEquals(expected,outContent.toString());
		assertEquals(result, 1);
	}
	@Test
	public void testBeDescisionMaker_2() 
	{
		//initialise variable
		int result;
		Player[] p ={new Player("a",1),new Player("b",2)};

		//for output
		final ByteArrayOutputStream outContent = new ByteArrayOutputStream();
		System.setOut(new PrintStream(outContent));
		
		MagicToolCard m = new MagicToolCard();	
		
		String expected = "Now, you use this card to be DecisionMaker!\n" +
		"Please input an integer.\n"+
		"The decision maker is: b.\n" +
		"Please input your decision (1-4): \n" ;
		
		//for input
		String data = "a 1 "; 	//data to be input 
		InputStream stdin = System.in; 
		try {   
			System.setIn(new ByteArrayInputStream(data.getBytes()));	//put data to input stream
			result = m.beDescisionMaker(1,p);	//for getting data from input stream
		} 
		finally {  
			System.setIn(stdin); 	//reset input stream as System.in
		} 
		
		//for testing
		assertEquals(expected,outContent.toString());
		assertEquals(result, 1);
	}
	@Test
	public void testBeDescisionMaker_3() 
	{
		//initialise variable
		int result;
		Player[] p ={new Player("a",1),new Player("b",2)};

		//for output
		final ByteArrayOutputStream outContent = new ByteArrayOutputStream();
		System.setOut(new PrintStream(outContent));
	
	
		MagicToolCard m = new MagicToolCard();	
		
		String expected = "Now, you use this card to be DecisionMaker!\n"  +
		"Please input an integer.\n"+		
		"The decision maker is: b.\n" +
		"Please input your decision (1-4): \n" +
		"Please input a number between 1 and 4.\n" +
		"Please input an integer.\n"+
		"The decision maker is: b.\n" +
		"Please input your decision (1-4): \n";
		
		//for input
		String data = "* 10 a 1 "; 	//data to be input 
		InputStream stdin = System.in; 
		try {   
			System.setIn(new ByteArrayInputStream(data.getBytes()));	//put data to input stream
			result = m.beDescisionMaker(1,p);	//for getting data from input stream
		} 
		finally {  
			System.setIn(stdin); 	//reset input stream as System.in
		} 
		
		//for testing
		assertEquals(expected,outContent.toString());
		assertEquals(result, 1);
	}

}
